﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.BLL;
using KPIS.GERP.GIMS.IBLL;
using KPIS.GERP.GIMS.MODEL;
using System.IO;

namespace KPIS.GERP.GIMS.APP.APP_UI.Edit_Form
{
    public partial class ICM_Delivery_Note : System.Web.UI.Page
    {
        Common.Main cn = new Common.Main();
        private bool isItemInEditMode = false;
        CommandControl cmdFac = new CommandControl();
        IBLLPersonal bllPersonal = new PersonalBLL();
        PurchaseOrderInstallmentBLL bllPoInstall = new PurchaseOrderInstallmentBLL();
        IBLLMasterWarehouse bllWh = new MasterWarehouseBLL();
        DeliveryNoteItemBLL bllDnItem = new DeliveryNoteItemBLL();
        DeliveryNoteCommitteeBLL bllDnCommittee = new DeliveryNoteCommitteeBLL();
        IBLLResourceMasterItem bllResItem = new ResourceMasterItemBLL();
        IBLLMasterCommitteeFunction bllComFunction = new MasterCommitteeFunctionBLL();
        IBLLMasterCommitteePosition bllComPosition = new MasterCommitteePositionBLL();
        IBLLHrmEmployee bllEmployee = new HrmEmployeeBLL();
        PurchaseOrderPenaltyBLL bllPoPenalty = new PurchaseOrderPenaltyBLL();
        DeliveryNotePenaltyBLL bllDnPenalty = new DeliveryNotePenaltyBLL();
        DeliveryNoteBLL bllDn = new DeliveryNoteBLL();
        IBLLDocument bllFile = new DocumentBLL();
        SysReportBLL bllReport = new SysReportBLL();
        double totalAmount = 0;
        double totalPoAmount = 0;
        int ItemsPerRequest = 10;

        protected void Page_Load(object sender, EventArgs e)
        {
            //RadComboBox cbWarehouse = new RadComboBox();

            rblExpenses.Items[0].Attributes.Add("onclick", "return WareHouse('" + cbWarehouse.ClientID + "')");
            rblExpenses.Items[1].Attributes.Add("onclick", "return Expenses('" + cbWarehouse.ClientID + "')"); 

            if (!IsPostBack)
            {
                LoadWarehouse();
                LoadCommitteePosition();
                LoadCommitteeFunction();
                GetPoDetail();
                GetDnDetail();
                TipConfirm.TargetControls.Add(btnConfirm.ClientID, true);
                tipCommitteeHistory.TargetControls.Add(History_Committee.ClientID, true);
            }
                       
        }

        public void RefreshDisplay()
        {
            RadManager1.ResponseScripts.Add(@"CloseActiveToolTip();");
        }

        protected int GetDnSeq()
        {
            int seq = Convert.ToInt32(Request.QueryString["Seq"]);
            return seq;
        }

        protected void Alert()
        {
            RadManager1.Alert(Session["Alert"].ToString());
        }

        protected void OnAjaxUpdate(object sender, ToolTipUpdateEventArgs args)
        {
            this.UpdateToolTip(args.Value, args.UpdatePanel);
        }

        private void UpdateToolTip(string elementID, UpdatePanel panel)
        {
            Control ctrl = Page.LoadControl("../UserControl/TIP_Delivery_Note_Confirm.ascx");
            ((KPIS.GERP.GIMS.APP.APP_UI.UserControl.TIP_Delivery_Note_Confirm)ctrl).RefreshParentDisplay = new CallBackHandle(RefreshDisplay);
            ((KPIS.GERP.GIMS.APP.APP_UI.UserControl.TIP_Delivery_Note_Confirm)ctrl).GetDnSeq = new CallBackHandleReturnInt(GetDnSeq);
            ((KPIS.GERP.GIMS.APP.APP_UI.UserControl.TIP_Delivery_Note_Confirm)ctrl).Alert = new CallBackHandleAlert(Alert);
            panel.ContentTemplateContainer.Controls.Add(ctrl);
        }

        protected void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e)
        {
            if (RadTabStrip1.SelectedTab.Value == "Detail")
            {
                GetPoDetail();
            }
            else if (RadTabStrip1.SelectedTab.Value == "Item")
            {
                LoadGridItem();
            }
            else if (RadTabStrip1.SelectedTab.Value == "Committee")
            {
                LoadGridCommittee();
            }
            else if (RadTabStrip1.SelectedTab.Value == "Penalty")
            {
                LoadPenaltyConclusion();
                LoadGridPenalty();
            }
            else if (RadTabStrip1.SelectedTab.Value == "File")
            {
                LoadGridFile();
            }
            else if (RadTabStrip1.SelectedTab.Value == "Report")
            {
                LoadGrid_Report();
            }
            else if (RadTabStrip1.SelectedTab.Value == "Progress")
            {
                LoadGridApprove();
                LoadGridInform();
                LoadGridRequest();
                LoadGridPublishing();
                LoadGridCommand();
                LoadGridCheck();
            }
        }

        private void btnDeny_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    bllPurchaseOrder.UpdatePurchaseOrderStatus(GetPoSeq(), SystemInfo._CancelRecordStatus);
            //    RadManager1.ResponseScripts.Add(@"CloseWindow();");
            //}
            //catch
            //{
            //    RadManager1.Alert(SystemInfo._InsertError);
            //}
        }

        protected void RadManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            string[] TmpArgument = e.Argument.Split(':');

            if (TmpArgument[0] == "SeqCommitteeClick")
            {
                LoadEditCommittee(Convert.ToInt32(TmpArgument[1]));
            }
            if (TmpArgument[0] == "SeqPenaltyClick")
            {
                LoadEditPenalty(Convert.ToInt32(TmpArgument[1]));
            }
            if (TmpArgument[0] == "ReportPdfClick")
            {
                RadManager1.ResponseScripts.Add(@"OpenReport('" + TmpArgument[1] + "','" + GetDnSeq() + "','pdf');");
            }
            if (TmpArgument[0] == "ReportWordClick")
            {
                RadManager1.ResponseScripts.Add(@"OpenReport('" + TmpArgument[1] + "','" + GetDnSeq() + "','word');");
            }
            if (TmpArgument[0] == "ReportExcelClick")
            {
                RadManager1.ResponseScripts.Add(@"OpenReport('" + TmpArgument[1] + "','" + GetDnSeq() + "','excel');");
            }
        }

        protected void ManageDisplay(string Status)
        {
            switch (Status)
            {
                case "A":
                case "P":
                    panelCommand_Detail.Visible = false;
                    panelCommand_Item.Visible = false;
                    panelCommand_Committee.Visible = false;
                    panelCommand_Penalty.Visible = false;
                    panelCommand_File.Visible = false;
                    btnConfirm.Visible = false;
                    btnDeny.Visible = true;
                    break;
                case "C":
                    panelCommand_Detail.Visible = false;
                    panelCommand_Item.Visible = false;
                    panelCommand_Committee.Visible = false;
                    panelCommand_Penalty.Visible = false;
                    panelCommand_File.Visible = false;
                    btnConfirm.Visible = false;
                    btnDeny.Visible = false;
                    break;
                case "N":
                case "R":
                case "W":
                    panelCommand_Detail.Visible = true;
                    panelCommand_Item.Visible = true;
                    panelCommand_Committee.Visible = true;
                    panelCommand_Penalty.Visible = true;
                    panelCommand_File.Visible = true;
                    btnConfirm.Visible = true;
                    btnDeny.Visible = false;
                    break;
            }
        }

        private static string GetStatusMessage(int offset, int total)
        {
            if (total <= 0)
                return "ไม่มีข้อมูล";

            return String.Format("รายการที่ <b>1</b>-<b>{0}</b> จากทั้งหมด <b>{1}</b> รายการ", offset, total);
        }

        //-----------------------------------------------------------------------------------------------

        #region tab ข้อมูลหลัก

        protected void LoadWarehouse()
        {
            IList<MasterWarehouseInfo> infoList = bllWh.GetMasterWarehouse();
            cbWarehouse.DataSource = infoList;
            cbWarehouse.DataBind();
        }

        protected void GetPoDetail()
        {
            PurchaseOrderInstallmentInfo info = bllPoInstall.GetPurchaseOrderInstallmentWithDeliveryNote(GetDnSeq());

            lblPoType.Text = info.InfoPurchaseOrder.InfoPoType.Name;
            lblPoRefNo.Text = info.InfoPurchaseOrder.Ref_No;
            lblPoName.Text = info.InfoPurchaseOrder.Name;
            panelInstallment.Visible = (info.InfoPurchaseOrder.CanInstallment == SystemInfo._YesStatus);
            lblInstallment.Text = info.InstallNumber.ToString(); ;
            lblSeller.Text = info.InfoPurchaseOrder.InfoBidder.InfoMasContact.Name_th;
            lblRedemptionAmount.Text = (info.RedemptionAmount != null ? Convert.ToDouble(info.RedemptionAmount).ToString("###,###,##0.00") : "0");
            lblDeductionAmount.Text = (info.DeductionAmount != null ? Convert.ToDouble(info.DeductionAmount).ToString("###,###,##0.00") : "0");
        }

        protected void GetDnDetail()
        {
            DeliveryNoteInfo info = new DeliveryNoteInfo();
            info = bllDn.GetDeliveryNote(GetDnSeq());

            txtDate.Text = ((DateTime)info.DeliveryDate).ToString("dd/MM/yyyy");
            txtName.Text = info.Name;
            txtDateDelivery.Text = ((DateTime)info.ReceiveDate).ToString("dd/MM/yyyy");
            rblExpenses.SelectedValue = info.BeExpenses.ToString();
            if (info.BeExpenses.ToString() == "0")
                cbWarehouse.SelectedValue = info.InfoWarehouse.Seq.ToString();
            txtDateInvoice.Text = (info.InvoiceDate != null ? ((DateTime)info.InvoiceDate).ToString("dd/MM/yyyy") : "");
            txtInvoiceNo.Text = info.InvoiceNumber;
            txtDocumentNumber.Text = info.DocumentNumber;
            txtDeliveryPlace.Text = info.DeliveryPlace;
            txtDescr.Text = info.Descr;

            lblStatus.Text = info.InfoRecordStatus.Name;
            hdSeq.Value = info.Seq.ToString();
            cmdFac.ViewCommand(panelList_Detail, panelGrid_Detail, panelCommand_Detail);
            ManageDisplay(info.InfoRecordStatus.Status);
            lblDeliveryDate.Text = ((DateTime)info.ReceiveDate).ToString("dd/MM/yyyy");            
        }

        protected void Edit_Detail_Click(object sender, EventArgs e)
        {
            cmdFac.EditCommand(panelList_Detail, panelGrid_Detail, panelCommand_Detail);
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "onclick", "VisibleWareHouse('" + rblExpenses.SelectedValue + "', '" + cbWarehouse.ClientID + "')", true);

            LoadValiDateDetail();
        }

        protected void EditSave_Detail_Click(object sender, EventArgs e)
        {
            DeliveryNoteInfo info = new DeliveryNoteInfo();
            RecordInfo infoRecord = new RecordInfo();
            MasterWarehouseInfo infoWarehouse = new MasterWarehouseInfo();

            infoRecord.Updated_by = Convert.ToInt32(Session["EmpSeq"].ToString());
            infoRecord.Updated_when = DateTime.Now;

            info.Seq = Convert.ToInt32(hdSeq.Value);
            info.DeliveryDate = Convert.ToDateTime(txtDate.TextWithLiterals);
            info.Name = txtName.Text;
            info.ReceiveDate = Convert.ToDateTime(txtDateDelivery.TextWithLiterals);
            info.InvoiceDate = (txtDateInvoice.Text.Length > 0 ? (Nullable<DateTime>)Convert.ToDateTime(txtDateInvoice.TextWithLiterals) : null);
            info.InvoiceNumber = txtInvoiceNo.Text;
            info.DocumentNumber = txtDocumentNumber.Text;
            info.Descr = txtDescr.Text;
            info.DeliveryPlace = txtDeliveryPlace.Text;
            info.BeExpenses = Convert.ToInt32(rblExpenses.SelectedValue);
            if (rblExpenses.SelectedValue == "0")
                infoWarehouse.Seq = string.IsNullOrEmpty(cbWarehouse.SelectedValue) ? (int?)null : Convert.ToInt32(cbWarehouse.SelectedValue);
            else
                infoWarehouse.Seq = null;

            info.InfoRecord = infoRecord;
            info.InfoWarehouse = infoWarehouse;

            if (rblExpenses.SelectedValue == "0")
            {
                RequiredFieldValidator valWarehouse = new RequiredFieldValidator();
                valWarehouse.ID = "ValcbWarehouse";
                valWarehouse.ControlToValidate = "cbWarehouse";
                valWarehouse.SetFocusOnError = true;
                valWarehouse.Display = ValidatorDisplay.Dynamic;
                valWarehouse.ErrorMessage = "* กรุณาระบุคลังพัสดุรับเข้า *";
                panelValcbWarehouse.Controls.Add(valWarehouse);
            }

            try
            {
                bllDn.Update(info);
                GetDnDetail();
            }
            catch
            {
                RadManager1.Alert(SystemInfo._InsertError);
            }
        }

        protected void Cancel_Detail_Click(object sender, EventArgs e)
        {
            GetDnDetail();
        }

        private void LoadValiDateDetail()
        {
            RequiredFieldValidator valDate = new RequiredFieldValidator();
            valDate.ID = "ValtxtDate";
            valDate.ControlToValidate = "txtDate";
            valDate.SetFocusOnError = true;
            valDate.Display = ValidatorDisplay.Dynamic;
            valDate.ErrorMessage = "* กรุณาระบุวันที่รายการ *";
            panelValtxtDate.Controls.Add(valDate);
            CustomValidator valCustomDate = new CustomValidator();
            valCustomDate.ID = "ValCustomDate";
            valCustomDate.ControlToValidate = "txtDate";
            valCustomDate.SetFocusOnError = true;
            valCustomDate.Display = ValidatorDisplay.Dynamic;
            valCustomDate.ErrorMessage = "* กรุณาระบุวันที่ให้ถูกต้อง *";
            valCustomDate.ClientValidationFunction = "validateDate";
            panelValtxtDate.Controls.Add(valCustomDate);
            RequiredFieldValidator valName = new RequiredFieldValidator();
            valName.ID = "ValtxtName";
            valName.ControlToValidate = "txtName";
            valName.SetFocusOnError = true;
            valName.Display = ValidatorDisplay.Dynamic;
            valName.ErrorMessage = "* กรุณาระบุเรื่อง *";
            panelValtxtName.Controls.Add(valName);
            RequiredFieldValidator valDeliveryDate = new RequiredFieldValidator();
            valDeliveryDate.ID = "ValtxtDateDelivery";
            valDeliveryDate.ControlToValidate = "txtDateDelivery";
            valDeliveryDate.SetFocusOnError = true;
            valDeliveryDate.Display = ValidatorDisplay.Dynamic;
            valDeliveryDate.ErrorMessage = "* กรุณาระบุวันที่ตรวจรับ *";
            panelValtxtDateDelivery.Controls.Add(valDeliveryDate);
            CustomValidator valCustomDeliveryDate = new CustomValidator();
            valCustomDeliveryDate.ID = "ValCustomDateDelivery";
            valCustomDeliveryDate.ControlToValidate = "txtDateDelivery";
            valCustomDeliveryDate.SetFocusOnError = true;
            valCustomDeliveryDate.Display = ValidatorDisplay.Dynamic;
            valCustomDeliveryDate.ErrorMessage = "* กรุณาระบุวันที่ตรวจรับให้ถูกต้อง *";
            valCustomDeliveryDate.ClientValidationFunction = "validateDate";
            panelValtxtDateDelivery.Controls.Add(valCustomDeliveryDate);            
            CustomValidator valCustomDateInvoice = new CustomValidator();
            valCustomDateInvoice.ID = "ValCustomDateInvoice";
            valCustomDateInvoice.ControlToValidate = "txtDateInvoice";
            valCustomDateInvoice.SetFocusOnError = true;
            valCustomDateInvoice.Display = ValidatorDisplay.Dynamic;
            valCustomDateInvoice.ErrorMessage = "* กรุณาระบุวันที่ให้ถูกต้อง *";
            valCustomDateInvoice.ClientValidationFunction = "validateDate";
            panelValtxtDateInvoice.Controls.Add(valCustomDateInvoice);
        }

        #endregion

        //-----------------------------------------------------------------------------------------------

        #region tab รายการพัสดุตรวจรับ

        protected void LoadGridItem()
        {
            IList<DeliveryNoteItemInfo> infoList = new List<DeliveryNoteItemInfo>();

            infoList = bllDnItem.GetDeliveryNoteItemWithParent(GetDnSeq());

            GridGroupByExpression ge = new GridGroupByExpression(Grid_Item.Columns[0]);
            Grid_Item.MasterTableView.GroupByExpressions.Add(ge);
            Grid_Item.DataSource = infoList;
            Grid_Item.DataBind();
            Edit_Item.Visible = true;
            EditSave_Item.Visible = false;
            Cancel_Item.Visible = false;
        }

        protected void Grid_Item_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridItem();
        }

        protected void Grid_Item_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                double price = 0;
                double poPrice = 0;
                GridDataItem dataBoundItem = e.Item as GridDataItem;

                double pricePerQty = Convert.ToDouble(dataBoundItem["PriceInVat"].Text);
                RadNumericTextBox txtQty = ((RadNumericTextBox)(dataBoundItem["Qty"].FindControl("txtQty")));
                RadNumericTextBox txtNetAmount = ((RadNumericTextBox)(dataBoundItem["NetAmount"].FindControl("txtNetAmount")));

                txtQty.Attributes.Add("onFocus", "return FocusQty('" + txtQty.ClientID + "','" + txtNetAmount.ClientID + "','" + pricePerQty + "')");
                txtQty.Attributes.Add("onBlur", "return BlurQty('" + txtQty.ClientID + "','" + txtNetAmount.ClientID + "','" + pricePerQty + "')");
                txtNetAmount.Attributes.Add("onFocus", "return FocusPrice('" + txtNetAmount.ClientID + "')");
                txtNetAmount.Attributes.Add("onBlur", "return BlurPrice('" + txtNetAmount.ClientID + "')");

                if (((RadNumericTextBox)(dataBoundItem["NetAmount"].FindControl("txtNetAmount"))).Value.ToString().Length > 0)
                {
                    price = double.Parse(((RadNumericTextBox)(dataBoundItem["NetAmount"].FindControl("txtNetAmount"))).Value.ToString());
                }

                if (((Label)(dataBoundItem["InfoPoInstallItem.NetAmount"].FindControl("lblPoNetAmount"))).Text.ToString().Length > 0)
                {
                    poPrice = double.Parse(((Label)(dataBoundItem["InfoPoInstallItem.NetAmount"].FindControl("lblPoNetAmount"))).Text.ToString());
                }

                totalAmount += price;
                totalPoAmount += poPrice;
            }
            else if (e.Item is GridFooterItem)
            {
                GridFooterItem footer = (GridFooterItem)e.Item;
                ((Label)footer["InfoPoInstallItem.NetAmount"].FindControl("lblTotalPoNetAmount")).Text = String.Format("{0:N3}", totalPoAmount);
                ((Label)footer["NetAmount"].FindControl("lblTotalNetAmount")).Text = String.Format("{0:N3}", totalAmount);
                ((RadNumericTextBox)footer["NetAmount"].FindControl("txtTotalNetAmount")).Value = Double.Parse(totalAmount.ToString());
            }
        }

        protected void Edit_Item_Click(object sender, EventArgs e)
        {
            this.IsItemInEditMode = true;
            LoadGridItem();
            Edit_Item.Visible = false;
            EditSave_Item.Visible = true;
            Cancel_Item.Visible = true;
        }

        protected void EditSave_Item_Click(object sender, EventArgs e)
        {
            IList<DeliveryNoteItemInfo> infoList = new List<DeliveryNoteItemInfo>();
            foreach (GridDataItem data in Grid_Item.MasterTableView.Items)
            {
                DeliveryNoteItemInfo info = new DeliveryNoteItemInfo();
                PurchaseOrderInstallmentItemInfo infoInstallItem = new PurchaseOrderInstallmentItemInfo();
                BidderQuotationInfo infoBidderQuotation = new BidderQuotationInfo();
                SysVatInfo infoVat = new SysVatInfo();
                ResourceMasterItemInfo infoItem = new ResourceMasterItemInfo();
                PurchaseRequestItemInfo infoPrItem = new PurchaseRequestItemInfo();
                BidderInfo infoBidder = new BidderInfo();
                RecordInfo infoRecord = new RecordInfo();
                string vat_percent = data["InfoPoInstallItem.InfoBidderQuotation.InfoBidder.VatPercent"].Text;

                info.Seq = Convert.ToInt32(data["Seq"].Text);
                info.Descr = ((TextBox)data["Descr"].FindControl("txtDescr")).Text;
                info.Qty = (((RadNumericTextBox)data["Qty"].FindControl("txtQty")).Text.Length > 0
                    ? Convert.ToInt32(((RadNumericTextBox)data["Qty"].FindControl("txtQty")).Text)
                    : 0);
                info.PriceExVat = Convert.ToDouble(data["PriceExVat"].Text);
                info.PriceInVat = Convert.ToDouble(data["PriceInVat"].Text);
                info.ExVatAmount = (Convert.ToDouble(info.Qty) * info.PriceExVat);
                info.NetAmount = (((RadNumericTextBox)data["NetAmount"].FindControl("txtNetAmount")).Text.Length > 0
                    ? Convert.ToInt32(((RadNumericTextBox)data["NetAmount"].FindControl("txtNetAmount")).Text)
                    : 0);
                info.VatAmount = Math.Round(Convert.ToDouble(info.NetAmount * (Convert.ToDouble(vat_percent) / (Convert.ToDouble(vat_percent) + 100))), 3);
                infoRecord.Updated_by = Int32.Parse(Session["EmpSeq"].ToString());
                infoRecord.Updated_when = DateTime.Now;

                info.InfoRecord = infoRecord;
                infoList.Add(info);
            }

            try
            {
                bllDnItem.Update(infoList);
                LoadGridItem();
            }
            catch
            {
                RadManager1.Alert(SystemInfo._InsertError);
            }
        }

        protected void Cancel_Item_Click(object sender, EventArgs e)
        {
            this.IsItemInEditMode = false;
            LoadGridItem();
            Edit_Item.Visible = true;
            EditSave_Item.Visible = false;
            Cancel_Item.Visible = false;
        }

        protected bool IsItemInEditMode
        {
            get { return this.isItemInEditMode; }
            set { this.isItemInEditMode = value; }
        }

        #endregion

        //-----------------------------------------------------------------------------------------------

        #region tab คณะกรรมการ

        protected void LoadGridCommittee()
        {
            IList<DeliveryNoteCommitteeInfo> infoList = bllDnCommittee.GetDeliveryNoteCommitteeWithParent(GetDnSeq());
            Grid_Committee.DataSource = infoList;
            GridGroupByExpression geFunction = new GridGroupByExpression(Grid_Committee.Columns[2]);
            GridGroupByExpression geRefNo = new GridGroupByExpression(Grid_Committee.Columns[3]);
            Grid_Committee.MasterTableView.GroupByExpressions.Add(geFunction);
            Grid_Committee.MasterTableView.GroupByExpressions.Add(geRefNo);
            Grid_Committee.DataBind();
            cmdFac.GridCommand(panelList_Committee, panelGrid_Committee, panelCommand_Committee);
        }

        protected void LoadCommitteeFunction()
        {
            IList<MasterCommitteeFunctionInfo> infoList = bllComFunction.GetMasterCommitteeFunction();
            cbCommitteeFunction.DataSource = infoList;
            cbCommitteeFunction.DataBind();
        }

        protected void LoadCommitteePosition()
        {
            IList<MasterCommitteePositionInfo> infoList = bllComPosition.GetMasterCommitteePosition();
            cbCommitteePosition.DataSource = infoList;
            cbCommitteePosition.DataBind();
        }

        protected void Grid_Committee_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridCommittee();
        }

        protected void rblCommitteeType_SelectedIndexChanged(object sender, EventArgs e)
        {
            panelInternal.Visible = (rblCommitteeType.SelectedValue == "1");
            panelExternal.Visible = (rblCommitteeType.SelectedValue == "2");
            LoadValidateCommittee();
        }

        protected void cbCommitteeInternalName_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            IList<HrmEmployeeInfo> infoList = bllEmployee.GetHrmEmployee(e.Text);
            int itemOffset = e.NumberOfItems;
            int endOffset = Math.Min(itemOffset + ItemsPerRequest, infoList.Count);
            e.EndOfItems = (endOffset == infoList.Count);
            int j = 0;
            for (int i = itemOffset; i < endOffset; i++)
            {
                cbCommitteeInternalName.Items.Add(new RadComboBoxItem(infoList[i].Name, infoList[i].Seq.ToString()));
                TableRow tr = new TableRow();
                TableCell tdJobSite = new TableCell();
                Label lblJobSite = new Label();
                lblJobSite.Text = infoList[i].InfoJobSite.Name;
                tdJobSite.Width = Unit.Pixel(200);
                tdJobSite.Controls.Add(lblJobSite);
                tr.Cells.Add(tdJobSite);
                TableCell tdName = new TableCell();
                Label lblName = new Label();
                lblName.Text = infoList[i].Name;
                tdName.Width = Unit.Pixel(150);
                tdName.Controls.Add(lblName);
                tr.Cells.Add(tdName);
                TableCell tdPosition = new TableCell();
                Label lblPosition = new Label();
                lblPosition.Text = infoList[i].InfoPosition.Name;
                tdPosition.Width = Unit.Pixel(150);
                tdPosition.Controls.Add(lblPosition);
                tr.Cells.Add(tdPosition);
                TableCell tdClass = new TableCell();
                Label lblClass = new Label();
                lblClass.Text = infoList[i].InfoClass.Name;
                tdClass.Width = Unit.Pixel(190);
                tdClass.Controls.Add(lblClass);
                tr.Cells.Add(tdClass);
                ((Table)cbCommitteeInternalName.Items[j].FindControl("tableCommmitteeInternalName")).Controls.Add(tr);
                j++;
            }

            e.Message = GetStatusMessage(endOffset, infoList.Count);
        }

        protected void ShowGrid_Committee_Click(object sender, EventArgs e)
        {
            LoadGridCommittee();
        }

        protected void Edit_Committee_Click(object sender, EventArgs e)
        {
            cmdFac.EditCommand(panelList_Committee, panelGrid_Committee, panelCommand_Committee);
            cmdFac.SetPanelList(panelInternal, "Edit");
            cmdFac.SetPanelList(panelExternal, "Edit");
            LoadValidateCommittee();
        }

        protected void AddNew_Committee_Click(object sender, EventArgs e)
        {
            cmdFac.AddNewCommand(panelList_Committee, panelGrid_Committee, panelCommand_Committee);
            LoadValidateCommittee();
            ClearCommittee();
        }

        protected void btnDelete_Committee_Click(object sender, EventArgs e)
        {
            IList<DeliveryNoteCommitteeInfo> infoList = new List<DeliveryNoteCommitteeInfo>();
            if (panelGrid_Committee.Visible)
            {
                foreach (GridDataItem data in Grid_Committee.MasterTableView.GetSelectedItems())
                {
                    DeliveryNoteCommitteeInfo info = new DeliveryNoteCommitteeInfo();
                    RecordInfo infoRecord = new RecordInfo();
                    info.Seq = Convert.ToInt32(data.OwnerTableView.DataKeyValues[data.ItemIndex]["Seq"]);
                    info.DeleteReason = txtDeleteReason.Text;
                    infoRecord.Updated_by = Int32.Parse(Session["EmpSeq"].ToString());
                    infoRecord.Updated_when = DateTime.Now;
                    info.InfoRecord = infoRecord;
                    infoList.Add(info);
                }
            }
            else
            {
                DeliveryNoteCommitteeInfo info = new DeliveryNoteCommitteeInfo();
                RecordInfo infoRecord = new RecordInfo();
                info.Seq = Convert.ToInt32(hdCommitteeSeq.Value);
                info.DeleteReason = txtDeleteReason.Text;
                infoRecord.Updated_by = Int32.Parse(Session["EmpSeq"].ToString());
                infoRecord.Updated_when = DateTime.Now;
                info.InfoRecord = infoRecord;
                infoList.Add(info);
            }

            if (infoList.Count == 0)
            {
                RadManager1.Alert(SystemInfo._DeleteNull);
                return;
            }

            try
            {
                bllDnCommittee.DeleteAll(infoList);
            }
            catch
            {
                RadManager1.Alert(SystemInfo._DeleteError);
                return;
            }

            LoadGridCommittee();
        }

        protected void Delete_Committee_Click(object sender, EventArgs e)
        {
            IList<DeliveryNoteCommitteeInfo> infoList = new List<DeliveryNoteCommitteeInfo>();
            if (panelGrid_Committee.Visible)
            {
                foreach (GridDataItem data in Grid_Committee.MasterTableView.GetSelectedItems())
                {
                    DeliveryNoteCommitteeInfo info = new DeliveryNoteCommitteeInfo();
                    info.Seq = Convert.ToInt32(data.OwnerTableView.DataKeyValues[data.ItemIndex]["Seq"]);
                    infoList.Add(info);
                }
            }
            else
            {
                DeliveryNoteCommitteeInfo info = new DeliveryNoteCommitteeInfo();
                info.Seq = Convert.ToInt32(hdCommitteeSeq.Value);
                infoList.Add(info);
            }

            if (infoList.Count == 0)
            {
                RadManager1.Alert(SystemInfo._DeleteNull);
                return;
            }

            try
            {
                bllDnCommittee.DeleteFromDB(infoList);
            }
            catch
            {
                RadManager1.Alert(SystemInfo._DeleteError);
                return;
            }

            LoadGridCommittee();
        }

        protected void AddNewSave_Committee_Click(object sender, EventArgs e)
        {
            DeliveryNoteCommitteeInfo info = new DeliveryNoteCommitteeInfo();
            HrmEmployeeInfo infoEmployee = new HrmEmployeeInfo();
            MasterCommitteePositionInfo infoPosition = new MasterCommitteePositionInfo();
            MasterCommitteeFunctionInfo infoFunction = new MasterCommitteeFunctionInfo();
            HrmEmployeeInfo infoEmployeeDetail = new HrmEmployeeInfo();
            RecordInfo infoRecord = new RecordInfo();
            SysCommitteeTypeInfo infoType = new SysCommitteeTypeInfo();
            DeliveryNoteInfo infoDn = new DeliveryNoteInfo();

            infoDn.Seq = GetDnSeq();
            info.Ref_no = Convert.ToInt32(txtCommitteeRefno.Value);
            infoType.Seq = Convert.ToInt32(rblCommitteeType.SelectedValue);
            infoType.Name = (rblCommitteeType.SelectedItem.Text);
            infoPosition.Seq = Convert.ToInt32(cbCommitteePosition.SelectedValue);
            infoPosition.Name = cbCommitteePosition.SelectedItem.Text;
            infoFunction.Seq = Convert.ToInt32(cbCommitteeFunction.SelectedValue);
            infoFunction.Name = cbCommitteeFunction.SelectedItem.Text;
            if (infoType.Seq == 1) //บุคลากรภายใน
            {
                infoEmployee.Seq = Convert.ToInt32(cbCommitteeInternalName.SelectedValue);
            }
            else
            {
                info.Ex_name = txtCommitteeExternalName.Text;
                info.Ex_descr = txtCommitteeExternalDescr.Text;
            }
            infoRecord.Created_by = cn.UserID;
            infoRecord.Created_when = DateTime.Now;
            info.InfoDn = infoDn;
            info.InfoType = infoType;
            info.InfoExployee = infoEmployee;
            info.InfoPosition = infoPosition;
            info.InfoFunction = infoFunction;
            info.InfoRecord = infoRecord;

            try
            {
                bllDnCommittee.Insert(info);
                LoadGridCommittee();
            }
            catch
            {
                RadManager1.Alert(SystemInfo._InsertError);
                return;
            }
        }

        protected void EditSave_Committee_Click(object sender, EventArgs e)
        {
            DeliveryNoteCommitteeInfo info = new DeliveryNoteCommitteeInfo();
            HrmEmployeeInfo infoEmployee = new HrmEmployeeInfo();
            MasterCommitteePositionInfo infoPosition = new MasterCommitteePositionInfo();
            MasterCommitteeFunctionInfo infoFunction = new MasterCommitteeFunctionInfo();
            HrmEmployeeInfo infoEmployeeDetail = new HrmEmployeeInfo();
            RecordInfo infoRecord = new RecordInfo();
            SysCommitteeTypeInfo infoType = new SysCommitteeTypeInfo();
            info.Seq = Convert.ToInt32(hdCommitteeSeq.Value);
            info.Ref_no = Convert.ToInt32(txtCommitteeRefno.Value);
            infoType.Seq = Convert.ToInt32(rblCommitteeType.SelectedValue);
            infoType.Name = (rblCommitteeType.SelectedItem.Text);
            infoPosition.Seq = Convert.ToInt32(cbCommitteePosition.SelectedValue);
            infoPosition.Name = cbCommitteePosition.SelectedItem.Text;
            infoFunction.Seq = Convert.ToInt32(cbCommitteeFunction.SelectedValue);
            infoFunction.Name = cbCommitteeFunction.SelectedItem.Text;
            if (infoType.Seq == 1) //บุคลากรภายใน
            {
                infoEmployee.Seq = Convert.ToInt32(cbCommitteeInternalName.SelectedValue);
            }
            else
            {
                info.Ex_name = txtCommitteeExternalName.Text;
                info.Ex_descr = txtCommitteeExternalDescr.Text;
            }
            infoRecord.Updated_by = Int32.Parse(Session["EmpSeq"].ToString());
            infoRecord.Updated_when = DateTime.Now;
            info.InfoType = infoType;
            info.InfoExployee = infoEmployee;
            info.InfoPosition = infoPosition;
            info.InfoFunction = infoFunction;
            info.InfoRecord = infoRecord;
            try
            {
                bllDnCommittee.Update(info);
                LoadGridCommittee();
            }
            catch
            {
                RadManager1.Alert(SystemInfo._InsertError);
                return;
            }
        }

        protected void Cancel_Committee_Click(object sender, EventArgs e)
        {
            LoadEditCommittee(Convert.ToInt32(hdCommitteeSeq.Value));
        }

        protected void ClearCommittee()
        {
            txtCommitteeRefno.Text = "";
            rblCommitteeType.Items[0].Selected = true;
            rblCommitteeType.Items[1].Selected = false;
            panelInternal.Visible = true;
            panelExternal.Visible = false;
            cbCommitteeInternalName.SelectedIndex = -1;
            cbCommitteeInternalName.Text = "";
            txtCommitteeExternalName.Text = "";
            txtCommitteeExternalDescr.Text = "";
            cbCommitteePosition.SelectedIndex = -1;
            cbCommitteePosition.Text = "";
            cbCommitteeFunction.SelectedIndex = -1;
            cbCommitteeFunction.Text = "";
        }

        protected void LoadEditCommittee(int ComSeq)
        {
            DeliveryNoteCommitteeInfo info = bllDnCommittee.GetDeliveryNoteCommittee(ComSeq);
            txtCommitteeRefno.Text = info.Ref_no.ToString();
            lblCommitteeRefNo.Text = info.Ref_no.ToString();
            rblCommitteeType.SelectedValue = info.InfoType.Seq.ToString();
            if (info.InfoType.Seq == 1)
            {
                panelInternal.Visible = true;
                panelExternal.Visible = false;
                cbCommitteeInternalName.SelectedValue = info.InfoExployee.Seq.ToString();
                cbCommitteeInternalName.Text = info.InfoExployee.Name;
                lblCommitteeInternalName.Text = info.InfoExployee.Name;
            }
            else
            {
                panelInternal.Visible = false;
                panelExternal.Visible = true;
                txtCommitteeExternalName.Text = info.Ex_name;
                txtCommitteeExternalDescr.Text = info.Ex_descr;
            }

            cbCommitteePosition.SelectedValue = info.InfoPosition.Seq.ToString();
            cbCommitteeFunction.SelectedValue = info.InfoFunction.Seq.ToString();
            cmdFac.ViewCommand(panelList_Committee, panelGrid_Committee, panelCommand_Committee);
            cmdFac.SetViewMode(panelInternal);
            cmdFac.SetPanelList(panelInternal, "View");
            cmdFac.SetViewMode(panelExternal);
            cmdFac.SetPanelList(panelExternal, "View");
        }

        protected void Grid_Committee_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                GridDataItem dataBoundItem = e.Item as GridDataItem;
                Image image = (Image)dataBoundItem["Image"].FindControl("Image1");
                if (dataBoundItem["InfoRecord.InfoStatus.Status"].Text == "W")
                {
                    image.ImageUrl = "../Image/Grid/Update.gif";
                }
                else
                {
                    image.ImageUrl = "../Image/Grid/Cancel.gif";
                }
            }
        }

        protected void LoadValidateCommittee()
        {
            RequiredFieldValidator valCommitteeRefno = new RequiredFieldValidator();
            valCommitteeRefno.ID = "ValtxtCommitteeRefno";
            valCommitteeRefno.ControlToValidate = "txtCommitteeRefno";
            valCommitteeRefno.SetFocusOnError = true;
            valCommitteeRefno.Display = ValidatorDisplay.Dynamic;
            valCommitteeRefno.ErrorMessage = "* กรุณาระบุชุดที่ *";
            panelValtxtCommitteeRefno.Controls.Add(valCommitteeRefno);
            RequiredFieldValidator valCommitteeInternalName = new RequiredFieldValidator();
            valCommitteeInternalName.ID = "ValcbCommitteeInternalName";
            valCommitteeInternalName.ControlToValidate = "cbCommitteeInternalName";
            valCommitteeInternalName.SetFocusOnError = true;
            valCommitteeInternalName.Display = ValidatorDisplay.Dynamic;
            valCommitteeInternalName.ErrorMessage = "* กรุณาระบุชื่อกรรมการ *";
            panelValcbCommitteeInternalName.Controls.Add(valCommitteeInternalName);
            RequiredFieldValidator valCommitteeExternalName = new RequiredFieldValidator();
            valCommitteeExternalName.ID = "ValtxtCommitteeExternalName";
            valCommitteeExternalName.ControlToValidate = "txtCommitteeExternalName";
            valCommitteeExternalName.SetFocusOnError = true;
            valCommitteeExternalName.Display = ValidatorDisplay.Dynamic;
            valCommitteeExternalName.ErrorMessage = "* กรุณาระบุชื่อกรรมการ *";
            panelValtxtCommitteeExternalName.Controls.Add(valCommitteeExternalName);
            RequiredFieldValidator valCommitteePosition = new RequiredFieldValidator();
            valCommitteePosition.ID = "ValcbCommitteePosition";
            valCommitteePosition.ControlToValidate = "cbCommitteePosition";
            valCommitteePosition.SetFocusOnError = true;
            valCommitteePosition.Display = ValidatorDisplay.Dynamic;
            valCommitteePosition.ErrorMessage = "* กรุณาระบุตำแหน่งกรรมการ *";
            panelValcbCommitteePosition.Controls.Add(valCommitteePosition);
            RequiredFieldValidator valCommitteeFunction = new RequiredFieldValidator();
            valCommitteeFunction.ID = "ValcbCommitteeFunction";
            valCommitteeFunction.ControlToValidate = "cbCommitteeFunction";
            valCommitteeFunction.SetFocusOnError = true;
            valCommitteeFunction.Display = ValidatorDisplay.Dynamic;
            valCommitteeFunction.ErrorMessage = "* กรุณาระบุหน้าที่กรรมการ *";
            panelValcbCommitteeFunction.Controls.Add(valCommitteeFunction);
        }

        protected void OnAjaxUpdateCommittee(object sender, ToolTipUpdateEventArgs args)
        {
            this.UpdateToolTipCommittee(args.Value, args.UpdatePanel);
        }

        private void UpdateToolTipCommittee(string elementID, UpdatePanel panel)
        {
            Control ctrl = Page.LoadControl("../UserControl/TIP_Purchase_Order_Committee_History.ascx");
            //((KPIS.GERP.GIMS.APP.APP_UI.UserControl.TIP_Purchase_Order_Committee_History)ctrl).GetBdSeq = new CallBackHandleReturnInt(GetBdSeq);
            panel.ContentTemplateContainer.Controls.Add(ctrl);
        }

        #endregion

        //-----------------------------------------------------------------------------------------------

        #region Tab ข้อมูลบันทึกสั่งปรับ

        protected void LoadPenaltyConclusion()
        {
            lblRealDeliveryDate.Text = txtDateDelivery.TextWithLiterals;
            DateTime startDate = Convert.ToDateTime(lblDeliveryDate.Text);
            DateTime endDate = Convert.ToDateTime(lblRealDeliveryDate.Text);

            if (Convert.ToDateTime(lblRealDeliveryDate.Text).CompareTo(Convert.ToDateTime(lblDeliveryDate.Text)) == 0)
            {
                lblResultDate.Text = "ส่งมอบตรงตามกำหนดเวลา";
            }
            else if (Convert.ToDateTime(lblRealDeliveryDate.Text).CompareTo(Convert.ToDateTime(lblDeliveryDate.Text)) < 0)
            {
                lblResultDate.Text = "ส่งมอบก่อนกำหนดเป็นเวลา " + (startDate - endDate).Days.ToString() + " วัน";
            }
            else if (Convert.ToDateTime(lblRealDeliveryDate.Text).CompareTo(Convert.ToDateTime(lblDeliveryDate.Text)) > 0)
            {
                lblResultDate.Text = "ส่งมอบช้ากว่ากำหนดเป็นเวลา " + (endDate - startDate).Days.ToString() + " วัน";
            }

            Nullable<double> sumAmount = 0;
            IList<DeliveryNoteItemInfo> infoList = new List<DeliveryNoteItemInfo>();

            foreach (DeliveryNoteItemInfo infoItem in bllDnItem.GetDeliveryNoteItemWithParent(GetDnSeq()))
            {
                sumAmount += infoItem.NetAmount;
            }

            lblItemSumAmount.Text = Convert.ToDouble(sumAmount).ToString("###,###,##0.00");
            hdSumAmount.Value = Convert.ToDouble(sumAmount).ToString("###,###,##0.00");
        }

        protected void LoadGridPenalty()
        {
            IList<DeliveryNotePenaltyInfo> infoList = bllDnPenalty.GetDeliveryNotePenaltyWithParent(GetDnSeq());
            Grid_Penalty.DataSource = infoList;
            Grid_Penalty.DataBind();

            cmdFac.GridCommand(panelList_Penalty, panelGrid_Penalty, panelCommand_Penalty);
        }

        protected void ShowGrid_Penalty_Click(object sender, EventArgs e)
        {
            LoadGridPenalty();
        }

        protected void AddNew_Penalty_Click(object sender, EventArgs e)
        {
            cmdFac.AddNewCommand(panelList_Penalty, panelGrid_Penalty, panelCommand_Penalty);
            LoadValidatePenalty();
            lblUnitCount.Text = "";
            lblPenaltyDescr.Text = "";
            lblUnitCount.Visible = true;
            lblPenaltyDescr.Visible = true;
        }

        protected void Edit_Penalty_Click(object sender, EventArgs e)
        {
            cmdFac.EditCommand(panelList_Penalty, panelGrid_Penalty, panelCommand_Penalty);
            LoadValidatePenalty();
            lblUnitCount.Visible = true;
            lblPenaltyDescr.Visible = true;
        }

        protected void Cancel_Penalty_Click(object sender, EventArgs e)
        {
            LoadEditPenalty(Convert.ToInt32(hdPenaltySeq.Value));
        }

        protected void Delete_Penalty_Click(object sender, EventArgs e)
        {
            IList<DeliveryNotePenaltyInfo> infoList = new List<DeliveryNotePenaltyInfo>();
            if (panelGrid_Penalty.Visible)
            {
                foreach (GridDataItem data in Grid_Penalty.MasterTableView.GetSelectedItems())
                {
                    DeliveryNotePenaltyInfo info = new DeliveryNotePenaltyInfo();
                    info.Seq = Convert.ToInt32(data.OwnerTableView.DataKeyValues[data.ItemIndex]["Seq"]);
                    infoList.Add(info);
                }
            }
            else
            {
                DeliveryNotePenaltyInfo info = new DeliveryNotePenaltyInfo();
                info.Seq = Convert.ToInt32(hdPenaltySeq.Value);
                infoList.Add(info);
            }

            if (infoList.Count == 0)
            {
                RadManager1.Alert(SystemInfo._DeleteNull);
                return;
            }

            try
            {
                bllDnPenalty.DeleteFromDB(infoList);
            }
            catch
            {
                RadManager1.Alert(SystemInfo._DeleteError);
                return;
            }

            LoadGridPenalty();
        }

        protected void AddNewSave_Penalty_Click(object sender, EventArgs e)
        {
            DeliveryNotePenaltyInfo info = new DeliveryNotePenaltyInfo();
            PurchaseOrderPenaltyInfo infoPoPenalty = new PurchaseOrderPenaltyInfo();
            DeliveryNoteInfo infoDn = new DeliveryNoteInfo();
            RecordInfo infoRecord = new RecordInfo();
            infoRecord.Created_by = Int32.Parse(Session["EmpSeq"].ToString());
            infoRecord.Created_when = DateTime.Now;

            string[] all_value = cbPenalty.SelectedValue.Split('|');
            infoPoPenalty.Seq = Convert.ToInt32(all_value[0]);
            info.Calculate = Convert.ToInt32(txtCalculate.Text);
            info.Amount = Convert.ToDouble(txtAmount.Text);
            info.FinalAmount = Convert.ToDouble(txtFinalAmount.Text);
            info.Remark = txtPenaltyRemark.Text;
            infoDn.Seq = GetDnSeq();

            info.InfoDn = infoDn;
            info.InfoRecord = infoRecord;
            info.InfoPoPenalty = infoPoPenalty;

            try
            {
                bllDnPenalty.Insert(info);
                LoadGridPenalty();
            }
            catch
            {
                RadManager1.Alert(SystemInfo._InsertError);
                return;
            }
        }

        protected void EditSave_Penalty_Click(object sender, EventArgs e)
        {
            DeliveryNotePenaltyInfo info = new DeliveryNotePenaltyInfo();
            PurchaseOrderPenaltyInfo infoPoPenalty = new PurchaseOrderPenaltyInfo();
            DeliveryNoteInfo infoDn = new DeliveryNoteInfo();
            RecordInfo infoRecord = new RecordInfo();
            infoRecord.Created_by = Int32.Parse(Session["EmpSeq"].ToString());
            infoRecord.Created_when = DateTime.Now;

            string[] all_value = cbPenalty.SelectedValue.Split('|');
            infoPoPenalty.Seq = Convert.ToInt32(all_value[0]);
            info.Seq = Convert.ToInt32(hdPenaltySeq.Value);
            info.Calculate = Convert.ToInt32(txtCalculate.Text);
            info.Amount = Convert.ToDouble(txtAmount.Text);
            info.FinalAmount = Convert.ToDouble(txtFinalAmount.Text);
            info.Remark = txtPenaltyRemark.Text;
            infoDn.Seq = GetDnSeq();
            infoRecord.Updated_by = Int32.Parse(Session["EmpSeq"].ToString());
            infoRecord.Updated_when = DateTime.Now;

            info.InfoDn = infoDn;
            info.InfoRecord = infoRecord;
            info.InfoPoPenalty = infoPoPenalty;

            try
            {
                bllDnPenalty.Update(info);
                LoadGridPenalty();
            }
            catch
            {
                RadManager1.Alert(SystemInfo._InsertError);
                return;
            }
        }

        protected void LoadValidatePenalty()
        {
            RequiredFieldValidator valPenalty = new RequiredFieldValidator();
            valPenalty.ID = "ValcbPenalty";
            valPenalty.ControlToValidate = "cbPenalty";
            valPenalty.SetFocusOnError = true;
            valPenalty.Display = ValidatorDisplay.Dynamic;
            valPenalty.ErrorMessage = "* กรุณาระบุกำหนดการปรับ *";
            panelValcbPenalty.Controls.Add(valPenalty);
            RequiredFieldValidator valAmount = new RequiredFieldValidator();
            valAmount.ID = "ValtxtFinalAmount";
            valAmount.ControlToValidate = "txtFinalAmount";
            valAmount.SetFocusOnError = true;
            valAmount.Display = ValidatorDisplay.Dynamic;
            valAmount.ErrorMessage = "* กรุณาระบุค่าปรับจริง *";
            panelValtxtFinalAmount.Controls.Add(valAmount);
            RequiredFieldValidator valCalculate = new RequiredFieldValidator();
            valCalculate.ID = "ValtxtCalculate";
            valCalculate.ControlToValidate = "txtCalculate";
            valCalculate.SetFocusOnError = true;
            valCalculate.Display = ValidatorDisplay.Dynamic;
            valCalculate.ErrorMessage = "* กรุณาระบุจำนวนที่ไม่ครบถ้วน *";
            panelValtxtCalculate.Controls.Add(valCalculate);
        }

        protected void cbPenalty_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            IList<PurchaseOrderPenaltyInfo> infoList = bllPoPenalty.GetPurchaseOrderPenaltyWithSearchFromDeliveryNote(GetDnSeq(), e.Text);
            int itemOffset = e.NumberOfItems;
            int endOffset = Math.Min(itemOffset + ItemsPerRequest, infoList.Count);
            e.EndOfItems = (endOffset == infoList.Count);
            int j = 0;
            for (int i = itemOffset; i < endOffset; i++)
            {
                cbPenalty.Items.Add(new RadComboBoxItem(infoList[i].Name, infoList[i].Seq.ToString()
                        + "|" + infoList[i].Name
                        + "|" + infoList[i].PenaltyDetail
                        + "|" + infoList[i].Rate.ToString()
                        + "|" + infoList[i].InfoPenaltyRateType.Name.ToString()
                        + "|" + infoList[i].InfoPenaltyCount.Name.ToString()
                        + "|" + infoList[i].Least.ToString()));
                TableRow tr = new TableRow();

                TableCell tdName = new TableCell();
                Label lblName = new Label();
                lblName.Text = infoList[i].Name;
                tdName.Width = Unit.Pixel(100);
                tdName.Controls.Add(lblName);
                tr.Cells.Add(tdName);

                TableCell tdDescr = new TableCell();
                Label lblDescr = new Label();
                lblDescr.Text = infoList[i].PenaltyDetail;
                tdDescr.Width = Unit.Pixel(250);
                tdDescr.Controls.Add(lblDescr);
                tr.Cells.Add(tdDescr);

                ((Table)cbPenalty.Items[j].FindControl("tablePenalty")).Controls.Add(tr);
                j++;
            }

            e.Message = GetStatusMessage(endOffset, infoList.Count);
        }

        protected void Grid_Penalty_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridPenalty();
        }

        protected void LoadEditPenalty(int pen_seq)
        {
            DeliveryNotePenaltyInfo info = bllDnPenalty.GetDeliveryNotePenalty(pen_seq);

            cbPenalty.Text = info.InfoPoPenalty.Name.ToString();
            cbPenalty.SelectedValue = info.InfoPoPenalty.Seq.ToString();
            txtCalculate.Text = info.Calculate.ToString();
            txtAmount.Text = info.Amount.ToString();
            txtFinalAmount.Text = info.FinalAmount.ToString();
            txtPenaltyRemark.Text = info.Remark;
            cmdFac.ViewCommand(panelList_Penalty, panelGrid_Penalty, panelCommand_Penalty);
            lblPenaltyDescr.Text = info.InfoPoPenalty.PenaltyDetail;
            lblPenalty.Text = info.InfoPoPenalty.Name;
            lblUnitCount.Text = info.InfoPoPenalty.InfoPenaltyCount.Name;
        }

        #endregion

        //-----------------------------------------------------------------------------------------------

        #region tab เอกสารแนบ

        protected void LoadGridFile()
        {
            Grid_File.DataSource = bllFile.GetDocument(GetDnSeq(), "ICM_DELIVERY_NOTE_FILE", "ICM_DN_SEQ", "ICM_DN_FILE_SEQ");
            Grid_File.DataBind();

            cmdFac.GridCommand(panelList_File, panelGrid_File, panelCommand_File);
        }

        protected void ShowGrid_File_Click(object sender, EventArgs e)
        {
            LoadGridFile();
        }

        protected void AddNew_File_Click(object sender, EventArgs e)
        {
            RequiredFieldValidator valFileName = new RequiredFieldValidator();
            valFileName.ID = "ValtxtFileName";
            valFileName.ControlToValidate = "txtFileName";
            valFileName.SetFocusOnError = true;
            valFileName.Display = ValidatorDisplay.Dynamic;
            valFileName.ErrorMessage = "* กรุณาระบุชื่อไฟล์ *";
            panelValtxtFileName.Controls.Add(valFileName);
            RequiredFieldValidator valAttachment = new RequiredFieldValidator();
            valAttachment.ID = "Valattachment";
            valAttachment.ControlToValidate = "attachment";
            valAttachment.SetFocusOnError = true;
            valAttachment.Display = ValidatorDisplay.Dynamic;
            valAttachment.ErrorMessage = "* กรุณาระบุที่อยู่ไฟล์ *";
            panelValattachment.Controls.Add(valAttachment);
            cmdFac.AddNewCommand(panelList_File, panelGrid_File, panelCommand_File);
        }

        protected void AddNewSave_File_Click(object sender, EventArgs e)
        {
            FileInfo infoFile = new FileInfo(hdSourceFile.Value);
            DocumentInfo info = new DocumentInfo();
            RecordInfo infoRecord = new RecordInfo();
            infoRecord.Created_by = Int32.Parse(Session["EmpSeq"].ToString());
            infoRecord.Created_when = DateTime.Now;
            info.File_info = infoFile;
            info.Name = txtFileName.Text;
            info.Dest_path = hdSourceFile.Value;
            info.InfoRecord = infoRecord;

            try
            {
                bllFile.InsertFileToDB(info, "ICM_DELIVERY_NOTE_FILE", "ICM_DN_SEQ", GetDnSeq());
            }
            catch
            {
                RadManager1.Alert(SystemInfo._InsertError);
                return;
            }

            LoadGridFile();
        }

        protected void Delete_File_Click(object sender, EventArgs e)
        {
            IList<DocumentInfo> infoList = new List<DocumentInfo>();
            foreach (GridDataItem data in Grid_File.MasterTableView.GetSelectedItems())
            {
                DocumentInfo info = new DocumentInfo();
                RecordInfo infoRecord = new RecordInfo();
                info.Seq = Convert.ToInt32(data.OwnerTableView.DataKeyValues[data.ItemIndex]["Seq"]);
                infoRecord.Updated_by = Int32.Parse(Session["EmpSeq"].ToString());
                infoRecord.Updated_when = DateTime.Now;
                info.InfoRecord = infoRecord;
                infoList.Add(info);
            }

            if (infoList.Count == 0)
            {
                RadManager1.Alert(SystemInfo._DeleteNull);
                return;
            }

            try
            {
                bllFile.DeleteFileFromDB(infoList, "ICM_DELIVERY_NOTE_FILE", "ICM_DN_FILE_SEQ");
            }
            catch
            {
                RadManager1.Alert(SystemInfo._DeleteError);
                return;
            }

            LoadGridFile();
        }

        protected void Grid_File_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridFile();
        }

        protected void OnAjaxRequestFile(object sender, AjaxRequestEventArgs e)
        {
            Control ctrl = Page.LoadControl("../UserControl/TIP_Delivery_Note_File_History.ascx");
            //((KPIS.GERP.GIMS.APP.APP_UI.UserControl.TIP_Purchase_Order_File_History)ctrl).GetPoSeq = new CallBackHandleReturnInt(GetPoSeq);
            RadAjaxPanel2.Controls.Add(ctrl);
        }

        #endregion

        //-----------------------------------------------------------------------------------------------

        #region tab ข้อมูลรายงาน

        protected void LoadGrid_Report()
        {
            IList<SysReportInfo> infoList = new List<SysReportInfo>();
            if (panelInstallment.Visible)
            {
                infoList = bllReport.GetReportName("DN_CONTRACT_APPROVE");
            }
            else
            {
                infoList = bllReport.GetReportName("DN_APPROVE");
            }
            Grid_Report.DataSource = infoList;
            Grid_Report.DataBind();
        }

        protected void Grid_Report_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGrid_Report();
        }

        #endregion

        //-----------------------------------------------------------------------------------------------

        #region ความคืบหน้า

        ProgressPurchaseOrderBLL bllPpo = new ProgressPurchaseOrderBLL();

        protected void LoadGridApprove()
        {
            IList<PurchaseOrderRouteInfo> InfoPprRouteList = bllPpo.GetPurchaseOrderApprove();
            RadGrid TmpGrid = (RadGrid)RadPanelBar1.FindItemByValue("Bar1").FindControl("GridApprove");
            TmpGrid.DataSource = InfoPprRouteList;
            TmpGrid.DataBind();
        }

        protected void LoadGridInform()
        {
            IList<PurchaseOrderRouteInfo> InfoPprRouteList = bllPpo.GetPurchaseOrderInform();
            RadGrid TmpGrid2 = (RadGrid)RadPanelBar1.FindItemByValue("Bar1").FindControl("GridInform");
            GridGroupByExpression g;
            TmpGrid2.DataSource = InfoPprRouteList;
            TmpGrid2.MasterTableView.GroupByExpressions.Clear();
            g = new GridGroupByExpression(TmpGrid2.Columns[0]);
            TmpGrid2.MasterTableView.GroupByExpressions.Add(g);

            TmpGrid2.Columns[0].Visible = false;
            TmpGrid2.DataBind();
        }

        protected void LoadGridRequest()
        {
            IList<PurchaseOrderInfo> InfoPpr = bllPpo.GetPurchaseRequest();
            RadGrid TmpGrid = (RadGrid)RadPanelBar1.FindItemByValue("Bar2").FindControl("GridRequest");
            TmpGrid.DataSource = InfoPpr;
            TmpGrid.DataBind();
        }

        protected void LoadGridPublishing()
        {
            IList<BidInfo> InfoBid = bllPpo.GetBid();
            RadGrid TmpGrid = (RadGrid)RadPanelBar1.FindItemByValue("Bar3").FindControl("GridPublishing");
            TmpGrid.DataSource = InfoBid;
            TmpGrid.DataBind();
        }

        protected void LoadGridCommand()
        {
            IList<PurchaseOrderInfo> InfopurOrder = bllPpo.GetPurchaseOrder();
            RadGrid TmpGrid = (RadGrid)RadPanelBar1.FindItemByValue("Bar4").FindControl("GridCommand");
            TmpGrid.DataSource = InfopurOrder;
            TmpGrid.DataBind();
        }

        protected void LoadGridCheck()
        {
            IList<DeliveryNoteInfo> InfoDeliveryNote = bllPpo.GetDeliveryNote();
            RadGrid TmpGrid = (RadGrid)RadPanelBar1.FindItemByValue("Bar5").FindControl("GridCheck");
            TmpGrid.DataSource = InfoDeliveryNote;
            TmpGrid.DataBind();
        }

        protected void GridApprove_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridApprove();
        }

        protected void GridHistory_ItemCommand(object source, GridCommandEventArgs e)
        {
            //LoadGridApproveHistory();
        }

        protected void GridInformHis_ItemCommand(object source, GridCommandEventArgs e)
        {
            //LoadGridInformHistory();
        }

        protected void GridInform_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridInform();
        }

        protected void GridRequest_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridRequest();
        }

        protected void GridRequest_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                GridDataItem dataBoundItem = e.Item as GridDataItem;
                Control target = e.Item.FindControl("lkName");
                Control targetRefNo = e.Item.FindControl("lkRefNo");
                if (!Object.Equals(target, null))
                {
                    if (!Object.Equals(this.TipApproveDetail, null))
                    {
                        this.TipApproveDetail.TargetControls.Add(target.ClientID, "Item:" + dataBoundItem["Ref_no"].Text + ":prr", true);
                        this.TipApproveDetail.TargetControls.Add(targetRefNo.ClientID, "Item:" + dataBoundItem["Ref_no"].Text + ":prr", true);
                    }
                }
            }
        }

        protected void GridPublishing_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridPublishing();
        }

        protected void GridPublishing_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                GridDataItem dataBoundItem = e.Item as GridDataItem;
                Control target = e.Item.FindControl("lkName");
                Control targetRefNo = e.Item.FindControl("lkRefNo");
                if (!Object.Equals(target, null))
                {
                    if (!Object.Equals(this.TipApproveDetail, null))
                    {
                        this.TipApproveDetail.TargetControls.Add(target.ClientID, "Item:" + dataBoundItem["Ref_no"].Text + ":br", true);
                        this.TipApproveDetail.TargetControls.Add(targetRefNo.ClientID, "Item:" + dataBoundItem["Ref_no"].Text + ":br", true);
                    }
                }
            }
        }

        protected void GridCommand_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridCommand();
        }

        protected void GridCommand_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                GridDataItem dataBoundItem = e.Item as GridDataItem;
                Control target = e.Item.FindControl("lkName");
                Control targetRefNo = e.Item.FindControl("lkRefNo");
                if (!Object.Equals(target, null))
                {
                    if (!Object.Equals(this.TipApproveDetail, null))
                    {
                        this.TipApproveDetail.TargetControls.Add(target.ClientID, "Item:" + dataBoundItem["Ref_no"].Text + ":por", true);
                        this.TipApproveDetail.TargetControls.Add(targetRefNo.ClientID, "Item:" + dataBoundItem["Ref_no"].Text + ":por", true);
                    }
                }
            }
        }

        protected void GridCheck_ItemCommand(object source, GridCommandEventArgs e)
        {
            LoadGridCheck();
        }

        protected void GridCheck_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                GridDataItem dataBoundItem = e.Item as GridDataItem;
                Control target = e.Item.FindControl("lkName");
                Control targetRefNo = e.Item.FindControl("lkRefNo");
                if (!Object.Equals(target, null))
                {
                    if (!Object.Equals(this.TipApproveDetail, null))
                    {
                        this.TipApproveDetail.TargetControls.Add(target.ClientID, "Item:" + dataBoundItem["Ref_no"].Text + ":dnr", true);
                        this.TipApproveDetail.TargetControls.Add(targetRefNo.ClientID, "Item:" + dataBoundItem["Ref_no"].Text + ":dnr", true);
                    }
                }
            }
        }

        protected void OnAjaxUpdate_AppDet(object sender, ToolTipUpdateEventArgs args)
        {
            this.UpdateToolTip_AppDet(args.Value, args.UpdatePanel);
        }

        private void UpdateToolTip_AppDet(string elementID, UpdatePanel panel)
        {
            string[] all_value = elementID.Split(new string[] { ":" }, StringSplitOptions.None);
            //if (all_value[0] == "Item")
            //{
            //    Session["Resource_Item_Id"] = all_value[1];
            //    Session["Expense_Id"] = null;
            //}
            //else
            //{
            //    Session["Resource_Item_Id"] = null;
            //    Session["Expense_Id"] = all_value[1];
            //}
            Session["RefNo"] = all_value[1];
            Session["DisType"] = all_value[2];
            Control ctrl = Page.LoadControl("../UserControl/TIP_Approve_Detail.ascx");
            panel.ContentTemplateContainer.Controls.Add(ctrl);
        }

        protected void OnAjaxUpdate_TipHistoryApprove(object sender, ToolTipUpdateEventArgs args)
        {
            this.UpdateToolTip_TipHistoryApprove(args.Value, args.UpdatePanel);
        }

        private void UpdateToolTip_TipHistoryApprove(string elementID, UpdatePanel panel)
        {
            string[] all_value = elementID.Split(new string[] { ":" }, StringSplitOptions.None);
            Session["HisSeq"] = all_value[1];
            Control ctrl;
            if (all_value[0] == "HisApprove")
            {
                ctrl = Page.LoadControl("../UserControl/ICM_PPR_RouteHistoryApprove.ascx");
            }
            else
            {
                ctrl = Page.LoadControl("../UserControl/ICM_PPR_RouteHistoryInform.ascx");
            }
            panel.ContentTemplateContainer.Controls.Add(ctrl);
        }

        protected void OnAjaxUpdate_TipHistoryInform(object sender, ToolTipUpdateEventArgs args)
        {
            this.UpdateToolTip_TipHistoryInform(args.Value, args.UpdatePanel);
        }

        private void UpdateToolTip_TipHistoryInform(string elementID, UpdatePanel panel)
        {
            string[] all_value = elementID.Split(new string[] { ":" }, StringSplitOptions.None);
            Session["HisSeq"] = all_value[1];
            Control ctrl;
            if (all_value[0] == "HisApprove")
            {
                ctrl = Page.LoadControl("../UserControl/ICM_PPR_RouteHistoryApprove.ascx");
            }
            else
            {
                ctrl = Page.LoadControl("../UserControl/ICM_PPR_RouteHistoryInform.ascx");
            }
            panel.ContentTemplateContainer.Controls.Add(ctrl);
        }

        protected void btnHistory_Click(object sender, EventArgs e)
        {

        }

        protected void btnHistory2_Click(object sender, EventArgs e)
        {

        }

        #endregion

        //-----------------------------------------------------------------------------------------------

        //#region tab รายการพัสดุเพิ่มเติม

        //protected void LoadGridExtra()
        //{
        //    IList<DeliveryNoteItemExtraInfo> infoList = new List<DeliveryNoteItemExtraInfo>();
        //    infoList = bllExtra.GetDeliveryNoteItemExtraWithParent(GetDnSeq());
        //    Grid_Extra.DataSource = infoList;
        //    Grid_Extra.DataBind();

        //    cmdFac.GridCommand(panelList_Extra, panelGrid_Extra, panelCommand_Extra);
        //}

        //protected void ShowGrid_Extra_Click(object sender, EventArgs e)
        //{
        //    LoadGridExtra();
        //}

        //protected void AddNew_Extra_Click(object sender, EventArgs e)
        //{
        //    cmdFac.AddNewCommand(panelList_Extra, panelGrid_Extra, panelCommand_Extra);
        //    LoadValidateExtra();
        //    lblItemUnit.Visible = true;
        //}

        //protected void Edit_Extra_Click(object sender, EventArgs e)
        //{
        //    cmdFac.EditCommand(panelList_Extra, panelGrid_Extra, panelCommand_Extra);
        //    LoadValidateExtra();
        //}

        //protected void Delete_Extra_Click(object sender, EventArgs e)
        //{
        //    IList<DeliveryNoteItemExtraInfo> infoList = new List<DeliveryNoteItemExtraInfo>();
        //    if (panelGrid_Extra.Visible)
        //    {
        //        foreach (GridDataItem data in Grid_Extra.MasterTableView.GetSelectedItems())
        //        {
        //            DeliveryNoteItemExtraInfo info = new DeliveryNoteItemExtraInfo();
        //            info.Seq = Convert.ToInt32(data.OwnerTableView.DataKeyValues[data.ItemIndex]["Seq"]);
        //            infoList.Add(info);
        //        }
        //    }
        //    else
        //    {
        //        DeliveryNoteItemExtraInfo info = new DeliveryNoteItemExtraInfo();
        //        info.Seq = Convert.ToInt32(hdSeq.Value);
        //        infoList.Add(info);
        //    }

        //    if (infoList.Count == 0)
        //    {
        //        RadManager1.Alert(SystemInfo._DeleteNull);
        //        return;
        //    }

        //    try
        //    {
        //        bllExtra.DeleteFromDB(infoList);
        //    }
        //    catch
        //    {
        //        RadManager1.Alert(SystemInfo._DeleteError);
        //        return;
        //    }

        //    LoadGridExtra();
        //}

        //protected void AddNewSave_Extra_Click(object sender, EventArgs e)
        //{
        //    IList<DeliveryNoteItemExtraInfo> infoList = new List<DeliveryNoteItemExtraInfo>();
        //    DeliveryNoteItemExtraInfo info = new DeliveryNoteItemExtraInfo();
        //    DeliveryNoteInfo infoDn = new DeliveryNoteInfo();
        //    ResourceMasterItemInfo infoResItem = new ResourceMasterItemInfo();
        //    MasterUnitInfo infoUnit = new MasterUnitInfo();
        //    RecordInfo infoRecord = new RecordInfo();

        //    infoRecord.Created_by = Int32.Parse(Session["EmpSeq"].ToString());
        //    infoRecord.Created_when = DateTime.Now;

        //    string[] all_value = cbItem.SelectedValue.Split('|');
        //    infoResItem.Seq = Convert.ToInt32(all_value[0]);
        //    infoResItem.Name = all_value[3];
        //    infoUnit.Name = all_value[2];
        //    infoDn.Seq = GetDnSeq();

        //    info.Descr = txtItemDescr.Text;
        //    info.Qty = Convert.ToInt32(txtItemQty.Text);
        //    info.Price = (txtItemPrice.Text.Length > 0 ? Convert.ToDouble(txtItemPrice.Text) : 0);
        //    info.Remark = txtItemDescr.Text;

        //    infoResItem.InfoUnit = infoUnit;
        //    info.InfoRecord = info.InfoRecord;
        //    info.InfoResItem = infoResItem;
        //    info.InfoDn = infoDn;
        //    infoList.Add(info);

        //    try
        //    {
        //        bllExtra.Insert(infoList);
        //        LoadGridExtra();
        //    }
        //    catch
        //    {
        //        RadManager1.Alert(SystemInfo._InsertError);
        //        return;
        //    }
        //}

        //protected void EditSave_Extra_Click(object sender, EventArgs e)
        //{
        //    //PurchaseOrderPenaltyInfo info = new PurchaseOrderPenaltyInfo();
        //    //SysPenaltyRateTypeInfo infoSysPenaltyRateType = new SysPenaltyRateTypeInfo();
        //    //SysPenaltyCountInfo infoPenaltyCount = new SysPenaltyCountInfo();
        //    //PurchaseOrderInfo infoPurchaseOrder = new PurchaseOrderInfo();
        //    //RecordInfo infoRecord = new RecordInfo();
        //    //info.Seq = Convert.ToInt32(hdPenaltySeq.Value);
        //    //info.Name = txtPenaltyName.Text;
        //    //info.Descr = txtPenaltyDescr.Text;
        //    //info.Rate = Convert.ToDouble(txtPenaltyRate.Text);
        //    //infoSysPenaltyRateType.Seq = Convert.ToInt32(cbPenaltyRateType.SelectedValue);
        //    //infoPenaltyCount.Seq = Convert.ToInt32(cbPenaltyCount.SelectedValue);

        //    //if (panelLeast.Visible && txtLeast.Text != "")
        //    //{
        //    //    info.Least = Convert.ToDouble(txtLeast.Text);
        //    //}

        //    //infoRecord.Updated_by = 1;
        //    //infoRecord.Updated_when = DateTime.Now;

        //    //info.InfoPenaltyRateType = infoSysPenaltyRateType;
        //    //info.InfoPenaltyCount = infoPenaltyCount;
        //    //info.InfoRecord = infoRecord;

        //    //try
        //    //{
        //    //    bllPoPenalty.Update(info);
        //    //    LoadGridPenalty();
        //    //}
        //    //catch
        //    //{
        //    //    RadManager1.Alert(SystemInfo._InsertError);
        //    //    return;
        //    //}
        //}

        //protected void Cancel_Extra_Click(object sender, EventArgs e)
        //{
        //    LoadEditExtra(Convert.ToInt32(hdExtraSeq.Value));
        //}

        //protected void LoadEditExtra(int extra_seq)
        //{
        //    //PurchaseOrderPenaltyInfo info = bllPoPenalty.GetPurchaseOrderPenalty(pen_seq);

        //    //hdPenaltySeq.Value = info.Seq.ToString();
        //    //txtPenaltyName.Text = info.Name;
        //    //txtPenaltyDescr.Text = info.Descr;
        //    //txtPenaltyRate.Text = info.Rate.ToString();
        //    //cbPenaltyRateType.SelectedValue = info.InfoPenaltyRateType.Seq.ToString();
        //    //cbPenaltyCount.SelectedValue = info.InfoPenaltyCount.Seq.ToString();
        //    //if (info.Least != null)
        //    //{
        //    //    txtLeast.Text = info.Least.ToString();
        //    //    panelLeast.Attributes.Add("style", "visibility:visible");
        //    //}
        //    //else
        //    //{
        //    //    panelLeast.Attributes.Add("style", "visibility:hidden");
        //    //}

        //    //cmdFac.ViewCommand(panelList_Penalty, panelGrid_Penalty, panelCommand_Penalty);
        //    //cmdFac.SetViewMode(panelLeast);
        //    //cmdFac.SetPanelList(panelLeast, "View");
        //}

        //protected void LoadValidateExtra()
        //{
        //    RequiredFieldValidator valItem = new RequiredFieldValidator();
        //    valItem.ID = "ValcbItem";
        //    valItem.ControlToValidate = "cbItem";
        //    valItem.SetFocusOnError = true;
        //    valItem.Display = ValidatorDisplay.Dynamic;
        //    valItem.ErrorMessage = "* กรุณาระบุรายการพัสดุ *";
        //    panelValcbItem.Controls.Add(valItem);
        //    RequiredFieldValidator valQty = new RequiredFieldValidator();
        //    valQty.ID = "ValtxtItemQty";
        //    valQty.ControlToValidate = "txtItemQty";
        //    valQty.SetFocusOnError = true;
        //    valQty.Display = ValidatorDisplay.Dynamic;
        //    valQty.ErrorMessage = "* กรุณาระบุจำนวน *";
        //    panelValItemQty.Controls.Add(valQty);
        //}

        //protected void cbItem_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        //{
        //    IList<ResourceMasterItemInfo> infoList = bllResItem.GetResourceMasterItemComboBoxWithSearch(e.Text);
        //    int itemOffset = e.NumberOfItems;
        //    int endOffset = Math.Min(itemOffset + ItemsPerRequest, infoList.Count);
        //    e.EndOfItems = (endOffset == infoList.Count);
        //    int j = 0;
        //    for (int i = itemOffset; i < endOffset; i++)
        //    {
        //        cbItem.Items.Add(new RadComboBoxItem(infoList[i].Name, infoList[i].Seq.ToString() + "|" + infoList[i].Descr + "|" + infoList[i].InfoUnit.Name + "|" + infoList[i].Name));
        //        TableRow tr = new TableRow();

        //        TableCell tdGroup = new TableCell();
        //        Label lblGroup = new Label();
        //        lblGroup.Text = infoList[i].InfoSubGroup.InfoGroup.Name;
        //        tdGroup.Width = Unit.Pixel(120);
        //        tdGroup.Controls.Add(lblGroup);
        //        tr.Cells.Add(tdGroup);

        //        TableCell tdSubGroup = new TableCell();
        //        Label lblSubGroup = new Label();
        //        lblSubGroup.Text = infoList[i].InfoSubGroup.Name;
        //        tdSubGroup.Width = Unit.Pixel(120);
        //        tdSubGroup.Controls.Add(lblSubGroup);
        //        tr.Cells.Add(tdSubGroup);

        //        TableCell tdName = new TableCell();
        //        Label lblName = new Label();
        //        lblName.Text = infoList[i].Name;
        //        tdName.Width = Unit.Pixel(120);
        //        tdName.Controls.Add(lblName);
        //        tr.Cells.Add(tdName);

        //        TableCell tdDescr = new TableCell();
        //        Label lblDescr = new Label();
        //        lblDescr.Text = infoList[i].Descr;
        //        tdDescr.Width = Unit.Pixel(200);
        //        tdDescr.Controls.Add(lblDescr);
        //        tr.Cells.Add(tdDescr);

        //        TableCell tdUnit = new TableCell();
        //        Label lblUnit = new Label();
        //        lblUnit.Text = infoList[i].InfoUnit.Name;
        //        tdUnit.Width = Unit.Pixel(90);
        //        tdUnit.Controls.Add(lblUnit);
        //        tr.Cells.Add(tdUnit);
        //        ((Table)cbItem.Items[j].FindControl("tableItem")).Controls.Add(tr);
        //        j++;
        //    }

        //    e.Message = GetStatusMessage(endOffset, infoList.Count);
        //}

        //protected void Grid_Extra_ItemCommand(object source, GridCommandEventArgs e)
        //{
        //    LoadGridExtra();
        //}

        //protected void backButton_Extra_Click(object sender, EventArgs e)
        //{
        //    RadManager1.ResponseScripts.Add(@"ChangeTab('Item',1);");
        //}

        //protected void nextButton_Extra_Click(object sender, EventArgs e)
        //{
        //    RadManager1.ResponseScripts.Add(@"ChangeTab('Committee',3);");
        //}

        //#endregion
    }
}
